<?php

namespace App\Http\Controllers;

use App\Models\Status;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class StatusesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function store(Request $request)
    {
        $this->validate($request,[
           'content' => 'required|max:100'
        ]);

        Auth::user()->statuses()->create([
           'content' => $request->input('content')
        ]);

        session()->flash('success','成功');

        return redirect()->back();
    }

    public function destroy(Status $status)
    {
        $this->authorize('destroy',$status);

        $status->delete();

        session()->flash('success','成功');

        return redirect()->back();
    }
}
